package org.smart4j.framework.common.helper;

import org.smart4j.framework.common.constant.ConfigConstant;
import org.smart4j.framework.common.util.PropertiesUtil;

import java.util.Properties;

/**
 * 项目配置文件助手类（smart.properties）
 *
 * @author YooLin1c
 * @version 1.0.0
 * @since 2018-01-29 12:44
 */
public final class ConfigHelper {
    private static final Properties CONFIG = PropertiesUtil.loadProps(ConfigConstant.CONFIG_FILE);

    public static String getJdbcDriver() {
        return CONFIG.getProperty(ConfigConstant.JDBC_DRIVER, "com.mysql.jdbc.Driver");
    }

    public static String getJdbcUrl() {
        return CONFIG.getProperty(ConfigConstant.JDBC_URL, "jdbc:mysql:///demo");
    }

    public static String getJdbcUsername() {
        return CONFIG.getProperty(ConfigConstant.JDBC_USERNAME, "root");
    }

    public static String getJdbcPassword() {
        return CONFIG.getProperty(ConfigConstant.JDBC_PASSWORD, "root");
    }

    public static String getAppBasePackage() {
        return CONFIG.getProperty(ConfigConstant.APP_BASE_PACKAGE, "org.smart4j");
    }

    public static String getAppJspPath() {
        return CONFIG.getProperty(ConfigConstant.APP_JSP_PATH, "/WEB-INF/view/");
    }

    public static String getAppAssetPath() {
        return CONFIG.getProperty(ConfigConstant.APP_ASSET_PATH, "/asset/");
    }

    public static int getDefaultFileSizeThreshold() {
        int value = PropertiesUtil.getInt(CONFIG, ConfigConstant.APP_UPLOAD_LIMIT, ConfigConstant.DEFAULT_FILE_SIZE_THRESHOLD);
        return value > 0 ? value : ConfigConstant.DEFAULT_FILE_SIZE_THRESHOLD;
    }
}
